package strain.expression;

import strain.IdGenerator;
import strain.domain.Domain;
import strain.solver.SolverState;

public abstract class BaseExpression<T, D extends Domain<T>> implements Expression<T,D> {
    
    protected final int id;
    
    public BaseExpression(final int id){
        this.id = id;
    }
    
    public BaseExpression(){
        this(IdGenerator.getNextId());
    }
    
    public void addTo(final SolverState solverState) {
        solverState.add(this);
    }
    
    public int getId(){
        return this.id;
    }
    
    @Override
    public boolean equals(final Object o){
        if (this == o) return true;
        if ((o == null) || !(this.getClass().isAssignableFrom(o.getClass()))) return false;
        BaseExpression<?,?> be = (BaseExpression<?,?>) o;
        return (be.id == this.id);
    }
    
    @Override
    public int hashCode(){
        return new Integer(this.id).hashCode();
    }
    
}
